﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter12.Code02.Code01
{
    public class Demo
    {
        public static void Begin()
        {
            {
                Nullable<int> nullableInt;
                nullableInt = null;
                Console.WriteLine(nullableInt);
                Console.ReadLine();
            }
            {
                var nullableInt = new Nullable<int>();
                if (nullableInt == null)
                {
                    Console.WriteLine("nullableInt is null.");
                }
                Console.ReadLine();

                if (!nullableInt.HasValue)
                {
                    Console.WriteLine("nullableInt has no Valus.");
                }
                Console.ReadLine();
            }
            {
                int? nullableInt;
                nullableInt = null;
                Console.WriteLine(nullableInt);
                Console.ReadLine();
            }
            {
                int? op1 = 5;
                int? result = op1 * 2;
            }
            {
                int? op1 = 5;
                int result = (int)op1 * 2;
            }
            {
                int? op1 = 5;
                int result = op1.Value * 2;
            }
            {
                int? op1 = null;
                int? op2 = 5;
                int? result = op1 * op2;
            }
            {
                int? op1 = 1;
                int? op2 = null;
                int? result1 = op1 ?? op2;
                int? result2 = op1 == null ? op2 : op1;
            }
            {
                int? op1 = null;
                int result = op1 * 2 ?? 5;
            }
            {
                int? op1 = null;
                int? result = op1 * 2 ?? 5;
            }
        }
    }
}
